<!DOCTYPE html >
<html>
<head>
    <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />
    
    <script src="../libraries/RGraph.common.core.js" ></script>
    <script src="../libraries/RGraph.common.dynamic.js" ></script>
    <script src="../libraries/RGraph.common.effects.js" ></script>
    <script src="../libraries/RGraph.drawing.text.js" ></script>
    <script src="../libraries/RGraph.bar.js" ></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <!--[if lt IE 9]><script src="../excanvas/excanvas.js"></script><![endif]-->
    
    <title>A Bar chart capable of drilldown</title>
    
    <meta name="description" content="A Bar chart that's capable of drilldown when you click on a bar" />
    
</head>
<body>

    <h1>A Bar chart capable of drilldown</h1>

    <canvas id="cvs" width="500" height="250">[No canvas support]</canvas><br />
    
    <button id="butBack">Show the overview chart</button>
    
    <script>
        $(document).ready(function ()
        {
            var ca = document.getElementById("cvs");
            var data           = [15,14,12,18,16,13];
            var data_drilldown = [];

            /**
            * The drilldown data - the order corresponds to that of the labels
            */
            data_drilldown.push([2,3,1,2,3,1,3]);
            data_drilldown.push([2,2,2,1,2,2,3]);
            data_drilldown.push([1,1,1,2,3,2,2]);
            data_drilldown.push([3,3,3,2,3,3,1]);
            data_drilldown.push([4,3,1,1,3,2,2]);
            data_drilldown.push([3,2,2,2,3,1,0]);

            var labels = ['John','Fred','Luis','Kevin','Lola','June']

            var bar = drawMainChart();
            
            /**
            * Draws the main chart
            */
            function drawMainChart ()
            {
                RGraph.reset(ca);

                var bar = new RGraph.Bar({
                    id: 'cvs',
                    data: data,
                    options: {
                        labels: labels,
                        bevel: !RGraph.ISOLD,
                        title: 'The whole teams statistics for sales of widgets',
                        background: {
                            grid: {
                                autofit: {
                                    numvlines: data.length
                                }
                            }
                        },
                        strokestyle:'rgba(0,0,0,0)'
                    }
                }).fadeIn();


            
                /**
                * When a bar is clicked show a more detailed breakdown
                */
                bar.onclick = function (e, shape)
                {
                    var obj = e.target.__object__;
                    var ca  = obj.canvas;
                    var idx = shape.index;



                    /**
                    * Slide the old bar out
                    */
                    obj.fadeOut(null, function ()
                    {
                        RGraph.reset(ca);
    
                        var bar = new RGraph.Bar({
                            id: 'cvs',
                            data: data_drilldown[idx],
                            options: {
                                labels: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
                                bevel: true,
                                strokestyle: 'rgba(0,0,0,0)',
                                title: 'Specific statistics for: ' + labels[idx],
                                background: {
                                    grid: {
                                        autfofit: {
                                            numvlines: 7
                                        }
                                    }
                                }
                            }
                        }).fadeIn();
                    });
                }
                
                /**
                * The onmousemove event to change the cursor
                */
                bar.onmousemove = function (e, shape)
                {
                    e.target.style.cursor = 'pointer';
                }
                
                return bar;
            }
            
            document.getElementById("butBack").onclick = function (e)
            {
                var obj = ca.__object__;

                obj.fadeOut(null,function ()
                {
                    var bar = drawMainChart();
                });
            }
        })
    </script>

    <p>
        <a href="./">&laquo; Back</a>
    </p>

</body>
</html>